import 'package:flutter/material.dart';
import 'package:flutter_business_2003a/provider/cart_provider.dart';
import 'package:flutter_business_2003a/provider/current_index_provider.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:flutter_business_2003a/provider/detail_info_provider.dart';
import 'package:provider/provider.dart';

import '../../bean/categoty_goods_list_bean_result.dart';

class DetailBottom extends StatelessWidget {
  const DetailBottom({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: ScreenUtil().setWidth(750).toDouble(),
      color: Colors.white,
      height: ScreenUtil().setHeight(80).toDouble(),
      child: Row(
        children: [
          //跳转购物车按钮
          Stack(
            children: [
              InkWell(
                onTap: () {
                  Provider.of<CurrentIndexProvider>(context, listen: false)
                      .changeIndex(2);
                  Navigator.pop(context);
                },
                child: Container(
                  width: ScreenUtil().setWidth(110).toDouble(),
                  alignment: Alignment.center,
                  child: const Icon(
                    Icons.shopping_cart,
                    size: 35,
                    color: Colors.red,
                  ),
                ),
              ),
              Positioned(
                top: 0,
                right: 0,
                child: Container(
                  padding: const EdgeInsets.fromLTRB(6, 3, 6, 3),
                  decoration: BoxDecoration(
                      color: Colors.pink,
                      border: Border.all(width: 1, color: Colors.white),
                      borderRadius: BorderRadius.circular(15.0)),
                  child: Text(
                    '${Provider.of<CartProvider>(context).allGoodsCount}',
                    style:
                        TextStyle(fontSize: ScreenUtil().setSp(20).toDouble(),color: Colors.white),
                  ),
                ),
              )
            ],
          ),
          //添加购物车按钮
          InkWell(
            onTap: () async {
              CategoryGoodsBean goodsBean =
                  Provider.of<DetailInfoProvider>(context, listen: false)
                      .goodsInfo!;
              await Provider.of<CartProvider>(context, listen: false).save(
                  goodsBean.id,
                  goodsBean.goods_desc,
                  1,
                  goodsBean.goods_default_price,
                  goodsBean.goods_default_icon,
                  true);
            },
            child: Container(
              alignment: Alignment.center,
              width: ScreenUtil().setWidth(320).toDouble(),
              height: ScreenUtil().setHeight(80).toDouble(),
              color: Colors.green,
              child: Text(
                '加入购物车',
                style: TextStyle(
                    color: Colors.white,
                    fontSize: ScreenUtil().setSp(28).toDouble()),
              ),
            ),
          ),
          //马上购买
          InkWell(
            onTap: () async {
              await Provider.of<CartProvider>(context, listen: false).remove();
            },
            child: Container(
              alignment: Alignment.center,
              width: ScreenUtil().setWidth(320).toDouble(),
              height: ScreenUtil().setHeight(80).toDouble(),
              color: Colors.red,
              child: Text(
                '马上购买',
                style: TextStyle(
                    color: Colors.white,
                    fontSize: ScreenUtil().setSp(28).toDouble()),
              ),
            ),
          )
        ],
      ),
    );
  }
}
